package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.dept.AddDeptDTO;
import com.qk.dto.dept.UpdateDeptDTO;
import com.qk.entity.Dept;
import com.qk.dto.dept.QueryPageDeptDTO;
import com.qk.management.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:gzc
 * @Date: 2025/09/29 21:05
 * @Description:
 */
@RestController
@RequestMapping("/depts")
@Slf4j
public class DeptController {


    @Autowired
    private DeptService deptService;


    @GetMapping
    public Result queryPage(QueryPageDeptDTO queryPageDeptDTO){
        log.info("部门分页参数：{}", queryPageDeptDTO);
        PageResult<Dept> pageResult = deptService.queryPage(queryPageDeptDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result addDept(@RequestBody AddDeptDTO addDeptDTO){
        log.info("添加部门：{}",addDeptDTO);
        deptService.addDept(addDeptDTO);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("查询部门信息,id：{}",id);
        Dept dept = deptService.queryById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result updateDept(@RequestBody UpdateDeptDTO updateDeptDTO){
        log.info("修改部门：{}",updateDeptDTO);
        deptService.updateDept(updateDeptDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable Integer id){
        log.info("删除部门,id：{}",id);
        deptService.deleteDept(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result queryAll() {
        log.info("查询所有部门信息");
        return  Result.success(deptService.queryAll());
    }

}
